// 验证
// 验证的关键字(key值)
const VerificationWords = ["required","regular"]
/**
 * 验证的信息对象
 * @param {Object} vaildateObj
 */
export const vaildates = (vaildateObj) => {
   
    const err = vaildateObj.err;
    
    for (const key of err) {
        const requireds = required(key,vaildateObj[vaildateObj.corresponding])
        if(requireds){
            return requireds
        }
        const regulars = regular(key,vaildateObj[vaildateObj.corresponding])
        if(regulars){
            return regulars
        }
    }
;
}


/**
 * 验证必填
 * @param {Array} err 
 * @param {String} content 
 */
function required(err,content){
    let start = false
    if(Object.keys(err).includes("required") && err["required"]){
        if(content){
            start = false
        } else {
            start = err.msg
        }
    }
    return start
}



// 验证正则
function regular(err,content){
    let start = false;
    if(Object.keys(err).includes("regular")){
        let regulars = typeof err["regular"] === "string" ? new RegExp(err["regular"].replace(/^['"]|['"]$/g)) : err["regular"]
        if(regulars.test(content)){
            start = false
        } else {
            start = err.msg
        }
    }
    return start
}